package jvm;

/**
 * @Author: ideaAdmin
 * TODO:类只能被加载一次 clinit方法也是如此
 * Date: 2022/2/12:10:42
 * Description:
 */

public class ClinitOneLoad {
    public static void main(String[] args) {
        Runnable runnable = () -> {
            System.out.println(Thread.currentThread().getName() + "进来了");
            Test test = new Test();
            System.out.println(Thread.currentThread().getName() + "结束了");
        };

        Thread thread = new Thread(runnable);
        Thread thread1 = new Thread(runnable);
        thread.start();
        thread1.start();
    }


}

class Test {
    static {
        if (true) {
            //只会被执行一次 因为类的 clinit 只能被执行一次
            System.out.println(Thread.currentThread().getName() + "正在加载这个类");
            while (true) {

            }
        }

    }
}
